#!/usr/bin/env python
"""
Module alphabet.
"""

###############################################################################

class Alphabet(object):
    """
    Abstract base class.
    """
    def __new__(t, *args, **kwargs):
        if not '_theInstance' in t.__dict__:
            t._theInstance = object.__new__(t)
        return t._theInstance

    def __init__(self):
        if self.__class__ is Alphabet:
            raise TypeError("Alphabet is an abstract class.")

###############################################################################
        
class UnambiguousRNAAlphabet(Alphabet):
    """
    Unambiguous RNA Alphabet.
    """
    _unambiguous_rna_letters = "GAUC"
    _ambiguous_rna_complement = {"A": "U",
                                 "C": "G",
                                 "G": "CU",
                                 "U": "AG",}
    def __iter__(self):
        return iter(UnambiguousRNAAlphabet._unambiguous_rna_letters)

    def complementaryBases(self, base):
        return UnambiguousRNAAlphabet._ambiguous_rna_complement[base]

###############################################################################
    
ambiguous_rna_letters   = "GAUCRYWSMKHBVDN"
unambiguous_rna_letters = "GAUC"

ambiguous_rna_values = {
    "A": "A",
    "C": "C",
    "G": "G",
    "U": "U",
    "M": "AC",
    "R": "AG",
    "W": "AU",
    "S": "CG",
    "Y": "CU",
    "K": "GU",
    "V": "ACG",
    "H": "ACU",
    "D": "AGU",
    "B": "CGU",
    "X": "GAUC",
    "N": "GAUC",
    }

ambiguous_rna_complement = {
    "A": "U",
    "C": "G",
    "G": "C",
    "U": "A",
    "M": "K",
    "R": "Y",
    "W": "W",
    "S": "S",
    "Y": "R",
    "K": "M",
    "V": "B",
    "H": "D",
    "D": "H",
    "B": "V",
    "X": "X",
    "N": "N",
    }

